package com.ikun.admin;

import com.ikun.admin.websocket.config.WebSocketConfig;
import com.ikun.admin.websocket.server.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * @ClassName XXXApplication
 * @Description:
 * @CreateDate: 2024/4/1 14:20
 */
@SpringBootApplication
@Slf4j
@EnableWebSecurity
public class AdminApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(AdminApplication.class, args);
//        WebSocketConfig.initTokenStoreBean(application);
        WebSocketConfig.init(applicationContext);
        Environment env = applicationContext.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String path = env.getProperty("server.servlet.context-path");
        String port = env.getProperty("server.port");

        WebSocketServer.init(applicationContext);
        log.info("\n----------------------------------------------------------\n\t" +
                "Application ikun-framework-java is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "Internal network: \t\thttp://" + ip + ":" + port + path + "/\n\t" +
                "Api Doc: \t\thttp://" + ip + ":" + port + path + "/swagger-ui/index.html\n" +
                "----------------------------------------------------------");
    }

}
